package com.yeepay.skb.biz;


import com.yeepay.skb.util.Conts;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class CustomerInforUpdatePartsBuilder extends YeepayBuilder{

    protected List<Part> parts = new ArrayList<Part>();
    protected String url= Conts.baseRequestUrl + "/customerInforUpdate.action";
    private String modifyTypeStr;
    private ArrayList<String> needHmac1=new ArrayList<>(Arrays.asList("mainCustomerNumber",
            "customerNumber",
            "whiteList",
            "freezeDays"));
    private ArrayList<String> needHmac2=new ArrayList<>(Arrays.asList("mainCustomerNumber",
            "customerNumber",
            "bankCardNumber",
            "bankName"));
    private ArrayList<String> needHmac3=new ArrayList<>(Arrays.asList("mainCustomerNumber",
            "customerNumber",
            "riskReserveDay",
            "manualSettle"));
    private ArrayList<String> needHmac4=new ArrayList<>(Arrays.asList("mainCustomerNumber",
            "customerNumber",
            "splitter",
            "splitterProfitFee"));
    private ArrayList<String> needHmac6=new ArrayList<>(Arrays.asList("mainCustomerNumber",
            "customerNumber",
            "bindMobile",
            "mailStr",
            "areaCode"));

    public Part[] generateParams() {
        return parts.toArray(new Part[parts.size()]);
    }

    public CustomerInforUpdatePartsBuilder setMainCustomerNumber(
            String mainCustomerNumber) {
        this.parts.add(new StringPart("mainCustomerNumber",
                mainCustomerNumber == null ? "" : mainCustomerNumber, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setCustomerNumber(
            String customerNumber) {
        this.parts.add(new StringPart("customerNumber",
                customerNumber == null ? "" : customerNumber, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setWhiteList(String whiteList) {
        this.parts.add(new StringPart("whiteList", whiteList == null ? ""
                : whiteList, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setFreezeDays(String freezeDays) {
        this.parts.add(new StringPart("freezeDays", freezeDays == null ? ""
                : freezeDays, "UTF-8"));
        return this;
    }

    public void setHmac(String hmac) {
        this.parts
                .add(new StringPart("hmac", hmac == null ? "" : hmac, "UTF-8"));
    }

    public CustomerInforUpdatePartsBuilder setModifyType(String modifyType) {
        this.parts.add(new StringPart("modifyType", modifyType == null ? ""
                : modifyType, "UTF-8"));
        modifyTypeStr=modifyType;
        return this;
    }

    public CustomerInforUpdatePartsBuilder setBankCardNumber(
            String bankCardNumber) {
        this.parts.add(new StringPart("bankCardNumber",
                bankCardNumber == null ? "" : bankCardNumber, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setBankName(String bankName) {
        this.parts.add(new StringPart("bankName", bankName == null ? ""
                : bankName, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setRiskReserveDay(
            String riskReserveDay) {
        this.parts.add(new StringPart("riskReserveDay",
                riskReserveDay == null ? "" : riskReserveDay, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setManualSettle(String manualSettle) {
        this.parts.add(new StringPart("manualSettle", manualSettle == null ? ""
                : manualSettle, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setSplitter(String splitter) {
        this.parts.add(new StringPart("splitter", splitter == null ? ""
                : splitter, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setSplitterProfitFee(
            String splitterProfitFee) {
        this.parts.add(new StringPart("splitterProfitFee",
                splitterProfitFee == null ? "" : splitterProfitFee, "UTF-8"));
        return this;
    }

    public CustomerInforUpdatePartsBuilder setBusiness(String business) {
        this.parts.add(new StringPart("business", business == null ? ""
                : business, "UTF-8"));
        return this;
    }

    @Override
    public List<String> needHmacArr() {
        if ("1".equals(modifyTypeStr)) {
            return needHmac1;
        }else if("2".equals(modifyTypeStr)){
            return needHmac2;
        }else if("3".equals(modifyTypeStr)){
            return needHmac3;
        }else if("4".equals(modifyTypeStr)){
            return needHmac4;
        }else if("6".equals(modifyTypeStr)){
            return needHmac6;
        }
        return null;
    }

    public List<Part> getParts() {
        return parts;
    }

    @Override
    public String getUrl() {
        return url;
    }
}
